<?php
class Helper_Function
{
	//去除HTML标记
	function mask_HTMLCODE($str)
	{
		return preg_replace("'(<[^<]*[^>]>)+'","",$str);
	}
	/**
	 * Description :checkNumber 判断是否为数字
	 * @param $str 需要检查的字符串
	 * @return boolean
	 */
	function checkNumber($str)
	{
		$reg = "/^\d+(\.\d+)?$/";
		return preg_match($reg, $str);
	}
	/**
	 * Description :checkInteger 判断是否为整数
	 * @param $str 需要检查的字符串
	 * @return boolean
	 */
	function checkInteger($str)
	{
		$reg = "/^[0-9]+$/";
		return preg_match($reg, $str);
	}
	/**
	 * 过滤SQL命令，防SQL注入
	 *
	 * @param $CheckString  需要过渡的字符串
	 * @return string
	 */
	function SqlfilterTitle($CheckString="")
	{
	  $search = array ("'<script[^>]*?>.*?</script>'si",  // 去掉 javascript
					 "'[\r\n]|[\s]+'",                 // 去掉空白字符
					 "'&(lt|#60);'i","'\''","'\\\'",
					 "'&(gt|#62);'i","'[<]|[>]'","'delete'i","'update'i","'sele'i","'insert'i",
					 "'into'i","'where'i","'set'i"
					 ,"'from'i","'script'i","'value'i","'exe'i","'localgroup'i","'chr'i",
					 "'truncate'i","'sysobjects'i","'syscolumns'i","'master'i","'/add'i","'cmdshell'i"
					 ,"'drop'i");
	  $replace = array ("");
	  return preg_replace($search, $replace,$CheckString);
	 }
	 // 过滤SQL命令，防SQL注入 去掉了对<>的正则
	function SqlfilterTitle2($CheckString="")
	{
	  $search = array ("'<script[^>]*?>.*?</script>'si",  // 去掉 javascript
					 "'[\r\n]|[\s]+'",                 // 去掉空白字符
					 "'&(lt|#60);'i","'\''","'\\\'",
					 "'&(gt|#62);'i","'delete'i","'update'i","'sele'i","'insert'i",
					 "'into'i","'where'i","'set'i"
					 ,"'from'i","'script'i","'value'i","'exe'i","'localgroup'i","'chr'i",
					 "'truncate'i","'sysobjects'i","'syscolumns'i","'master'i","'/add'i","'cmdshell'i"
					 ,"'drop'i");
	  $replace = array ("");
	  return preg_replace($search, $replace,$CheckString);
	 }
	 /**
	* Description :csubstr 截取字符串
	* @param $string　(字符串　字符串类型)
	* @param $start　(开始截取位置　整型)
	* @param $length　(截取长度　整型)
	* return String (返回字符串)
	*/
	function Csubstr($string,$start=0,$length=0,$tail='')
	{
		$l = $length;
		if($l == 0)$l = strlen($string);
		if($start< 0 || $l < 0)
		{
			return $string;
		}
		if(($start+$l) >= strlen($string))
		{
			return substr($string,$start,$l);
		}
		else
		{
			$j=0;
			$num=$l;
			for($i=$start; $i< $num-1;$i++)
			{
				if(ord(substr($string,$i,1))>0xa0) $j++;
			}
			if($j%2!=0)
			{
				$num=$num+1;
			}else
			{
				$num=$num;
			}
			return substr($string,$start,$num-1).$tail;
		}
	}
}
?>